/* 
 * File:   AudioRecorder.h
 * Author: Tung Mai
 *
 * Created on June 18, 2010, 10:36 AM
 */

#ifndef _AUDIORECORDER_H
#define	_AUDIORECORDER_H

//#include <Carbon/Carbon.h>
#include <AudioUnit/AudioUnit.h>
#include <AudioToolbox/AudioToolbox.h>

class AudioRecorder {
public:
    AudioRecorder();
    virtual ~AudioRecorder();

    OSStatus ConfigureOutputFile(const char* inParentDir, const char* inFileName,
            AudioStreamBasicDescription* inASBD);
    OSStatus Configure(const char* inParentDir, const char* inFilename,
            AudioStreamBasicDescription* inASBD);
    OSStatus Start();
    OSStatus Stop();
    OSStatus ConfigureInputDevice(AudioDeviceID* inDeviceID);

private:
    AudioBufferList *fAudioBuffer;
    AudioUnit fAudioUnit;
    ExtAudioFileRef fOutputAudioFile;
    AudioStreamBasicDescription fOutputFormat;

    OSStatus ConfigureAU();
    static OSStatus AudioInputProc(void* inRefCon, AudioUnitRenderActionFlags* ioActionFlags, const AudioTimeStamp* inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList* ioData);
    AudioBufferList *AllocateAudioBufferList(UInt32 numChannels, UInt32 size);
    void DestroyAudioBufferList(AudioBufferList* list);
};

#endif	/* _AUDIORECORDER_H */

